package com.example.wxy.bbtapp.Receivers;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import com.example.wxy.bbtapp.Common.ServiceHelper;
import com.example.wxy.bbtapp.MainActivity;
import com.example.wxy.bbtapp.Service.BBTService;
import com.example.wxy.bbtapp.Service.BindService;
import com.example.wxy.bbtapp.myApplication;

/**
 * Created by yons on 2017/9/10.
 */

public class BootBroadcastReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub

        if(LoadData())
        {
            if(!ServiceHelper.isServiceRunning(context, "BBTServices")) {
                // 开启服务
                context.startService(new Intent(context, BBTService.class));
            }
        }
        else
        {
            Intent main=new Intent(context,MainActivity.class);
            main.setAction("android.intent.action.MAIN");
            main.addCategory("android.intent.category.LAUNCHER");
            main.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(main);
        }
    }

    private  boolean LoadData()
    {
        myApplication.bindinofs = BindService.LoadBindInfo();

        return myApplication.bindinofs != null;
    }
}
